<?php
namespace app\home\controller;
use think\Controller;
use think\Db;
use myResponse\Res;
use think\Session;

class Login  extends Controller
{

    public function index(){

        $uname =input('post.username');
        $upwd = input('post.password');
        $map['LoginName']=$uname;
        $map['UserPwd']=md5($upwd);
        $map['UserState']='Y';
        $res =Db::name('sys_user')->where($map)->find();

//        de($res);
        if($res['UserId']){
            $ro =Db::name('sys_role')->where('RoleId ='.$res['RoleId'])->find();
            $depart =Db::name('sys_department')->where('DeptId ='.$res['DeptId'])->find();
            $res['role']=$ro;
            $res['depart']=$depart;
//            Session::set('u_id',$res['u_id'],'user'); // 赋值user作用域
            session('user.UserId',$res['UserId']);
            session('user.UserName',$res['UserName']);
            session('user.LoginName',$res['LoginName']);
            session('user.RoleId',$res['RoleId']);
            Res::suc('登录成功',$res);
        }else{
            Res::errs('未注册用户 或 用户名/密码 错误!');
        }
    }

    public function logout(){
        session::delete('user');
//        session::delete('u_name');
        $this->redirect('/index.php/login');
    }

    /*登录*/
    public function index2()
    {
        $arr = [
            'headerUrl'=> "http://njchome.b0.upaiyun.com/hlsnzj/default_header.jpg",
            'mobile'=> "123456",
            'nickname'=> "昵称",
            'postcode'=> "",
            'updatedTime'=> "2019-05-27 17:35:28",
            'username'=> "admin",
            'id'=> 1
        ];
/*address: ""
brief: "无"
company: {_id: 1, area: {_id: 1, areaName: "江苏", freeze: false, createdTime: "2019-05-09 16:39:16",…},…}
createdTime: "2019-05-09 16:39:18"
faxno: ""
freeze: false
headerUrl: "http://njchome.b0.upaiyun.com/hlsnzj/default_header.jpg"
mobile: "123456"
nickname: "昵称"
postcode: ""
updatedTime: "2019-05-27 17:35:28"
username: "admin"
_id: 1
echo 44;*/
//        $ll = Db::table('sys_user')->select();
//
//        dump($ll);
    }

    public function aaa($name = 'aaa')
    {

//        $ret=Res::suc(1,[11,22]);
//        dd($ret) ;
        $ll = Db::table('sys_user')->select();
        dd($ll);
        return 'hello,' . $name;
    }
    public function bbb($name = 'bbb')
    {
        return 'hello,' . $name;
    }
}
